package com.useeinfo.oa.modules.inspection.biz;

import com.useeinfo.framework.extend.biz.CrudBiz;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.oa.modules.inspection.dao.PlannerInspectionLogDao;
import com.useeinfo.oa.modules.inspection.entity.PlannerInspection;
import com.useeinfo.oa.modules.inspection.entity.PlannerInspectionLog;
import com.useeinfo.oa.modules.inspection.enums.InsOrderOperationEnum;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import com.useeinfo.oa.modules.security.util.SessionKeyUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;


@Service
public class PlannerInspectionLogBiz extends CrudBiz<PlannerInspectionLogDao, PlannerInspectionLog> {

    public void savePlannerLog(PlannerInspection plannerInspection, InsOrderOperationEnum insOrderOperationEnum, HttpServletRequest request){
        SystemUser systemUser=SessionKeyUtils.getSessionUser(request);
        PlannerInspectionLog plannerInspectionLog=new PlannerInspectionLog();
        plannerInspectionLog.setPlannerInspection(plannerInspection);
        plannerInspectionLog.setEnterprise(SessionKeyUtils.getSessionEnterprise(request));
        plannerInspectionLog.setSystemUser(systemUser);
        plannerInspectionLog.setUserName(systemUser.getUserName());
        String detail=systemUser.getUserName()+"在"+DateTimeUtils.formatDateToStringWithTime(new Date())+","
                +insOrderOperationEnum.getName()+"，操作计划工单名称为："+plannerInspection.getName()+",编号为："+plannerInspection.getId();
        plannerInspectionLog.setDetail(detail);
        plannerInspectionLog.setInsOrderOperationEnum(insOrderOperationEnum);
        dao.add(plannerInspectionLog);
    }
}
